package fwx.service.impl;

import fwx.dao.BarberDao;
import fwx.dao.UserDao;
import fwx.dao.impl.BarberImpl;
import fwx.dao.impl.UserDaoImpl;
import fwx.dto.PageDto;
import fwx.model.Barber;
import fwx.model.User;
import fwx.service.BarberService;

import java.util.List;

public class BarberServiceImpl implements BarberService {
    private BarberDao barberDao = new BarberImpl();
    private UserDao userDao = new UserDaoImpl();

    @Override
    public List<Barber> findAll() {
        return barberDao.findAll();
    }

    @Override
    public int deleteBarber(int id) {
        return barberDao.deleteBarber(id);
    }

    @Override
    public int updateBarber(Barber barber) {
        return barberDao.updateBarber(barber);
    }


    @Override
    public int addBarber(Barber barber) {
        return barberDao.addBarber(barber);
    }

    @Override
    public boolean exist(User user) {
        return userDao.exist(user);
    }

    @Override
    public int addUser(User user) {
        return userDao.addUser(user);
    }

    @Override
    public int delete(int id) {
        return userDao.delete(id);
    }

    @Override
    public User findUser(User user) {
        return userDao.findUser(user);
    }

    @Override
    public Barber findById(int id) {
        return barberDao.finById(id);
    }

    @Override
    public PageDto<Barber> listBarber(int page, int pageSize) {
        int tatalRecord = barberDao.totalRecord();
        int from = (page-1) * pageSize;
        List<Barber> list = barberDao.findListByBarber(from,pageSize);
        PageDto<Barber> pageDto = new PageDto<>(page,pageSize,tatalRecord);
        pageDto.setList(list);
        return pageDto;
    }
    @Override
    public User findUserByName(String userName) {
        return userDao.findUserByName(userName);
    }

    @Override
    public List<User> findUserAll() {
        return userDao.findUserAll();
    }

    @Override
    public List<Barber> findBarberByName(String name) {
        return barberDao.findBarberByName(name);
    }
}
